package web.suzy.oj.controller.admin;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.pojo.dto.LoginDTO;
import web.suzy.oj.pojo.vo.UserInfoVO;
import web.suzy.oj.service.admin.account.AdminAccountService;

/**
 * YangSuzy 软件工作室
 * 类名: AdminAccountController
 * 描述: 管理员账户控制器
 * 功能: 处理管理员账户登录登出
 *
 * @author YangSuzy
 * Date: 2022/11/17 16:20
 */
@RestController
@RequestMapping("/api/admin")
public class AdminAccountController {
    @Autowired
    private AdminAccountService adminAccountService;

    /**
     * 方法名: login
     * 描述: 管理员登录
     *
     * @param loginDto
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.UserInfoVO>
     * @date 2022/11/17 16:27
     * @auther YangSuzy
     **/
    @PostMapping("/login")
    public ResultBean<UserInfoVO> login(@Validated @RequestBody LoginDTO loginDto) {
        return adminAccountService.login(loginDto);
    }

    /**
     * 方法名: logout
     * 描述: 管理员登出
     *
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/17 16:27
     * @auther YangSuzy
     **/
    @GetMapping("/logout")
    @RequiresAuthentication
    @RequiresRoles(value = {"root", "admin", "problem_admin"}, logical = Logical.OR)
    public ResultBean<Void> logout() {
        return adminAccountService.logout();
    }
}
